package com.huaruan.food.biz.admin.order.impl;

import java.util.List;

import com.huaruan.food.biz.admin.food.IFoodTypeManager;
import com.huaruan.food.biz.admin.order.IOrderManager;
import com.huaruan.food.dao.IDao;
import com.huaruan.food.entity.OrderDetail;
import com.huaruan.food.entity.OrderInfo;
import com.huaruan.food.javabean.PageObj;

public class OrderManagerImp implements IOrderManager {
	private IDao dao;
	private IFoodTypeManager tm;

	public void setTm(IFoodTypeManager tm) {
		this.tm = tm;
	}

	public void setDao(IDao dao) {
		this.dao = dao;
	}

	@Override
	public PageObj<OrderInfo> findOrderInfos(PageObj<OrderInfo> pageObj,
			int state) {
		List<OrderInfo> result = null;
		if (state == 0) {
			result = dao.find(pageObj.getQueryObj(), pageObj.getCurrPage(),
					pageObj.getRows(), "createTime", true);
		} else {
			result = dao.findByNamedQuery("findOrderInfos",
					pageObj.getCurrPage(), pageObj.getRows(), state);
		}
		if (null != result && result.size() > 0) {
			pageObj.setResults(result);
			pageObj.setAllRows(dao.listCount(pageObj.getQueryObj()));
		}
		return pageObj;
	}

	@Override
	public List<OrderDetail> findOrderDetailOrderId(int orderId) {
		return dao.findByNamedQuery("findOrderDetailOrderId", orderId);
	}

}
